<template>
  <el-form ref="form" :model="listQuery">

    <el-form-item>
      <el-input
        placeholder="请输入姓名或手机号"
        style="width: 200px"
        v-model="listQuery.params"
      ></el-input>
      <el-button type="primary" 
      style="margin-left: 10px" @click="getPage()">
      查询</el-button>
    </el-form-item>

  </el-form>

  <!-- <div>
    <el-button type="primary" style="margin-bottom: 10px" @click="add()"
      >添加</el-button>
  </div> -->

  <el-table :data="tableData" border style="width: 100%">
    <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
    <el-table-column prop="userName" label="用户姓名" width="180" align="center"></el-table-column>
    <el-table-column
      prop="modeTime"
      label="上次访问日期"
      width="120"
      align="center"
    >
    </el-table-column>
    <el-table-column
      prop="wwwnet"
      label="上次访问网站"
      width="200"
      align="center"
    >
    </el-table-column>
    
    <el-table-column
      prop="longtime"
      label="上次访问时长/h"
      width="200"
      align="center"
    >
    </el-table-column>

    <!-- 操作 -->
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button @click="update(scope.row)" type="primary">修改</el-button>
        <el-button @click="remove(scope.row)" type="danger">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    style="float: right"
    background
    layout="total,prev, pager, next"
    @current-change="getPage"
    :total="listQuery.total"
  >
  </el-pagination>
  <!-- 添加/修改 -->
  <el-dialog title="添加/修改" width="500px" v-model="addOrUpdateVisible">
    <el-form :model="addForm">
      <el-form-item label="姓名" label-width="80px">
        <el-input v-model="addForm.userName" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="手机号" label-width="80px">
        <el-input v-model="addForm.mobileNumber" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="sex" label-width="80px">
        <el-radio v-model="addForm.sex" :label="1">男</el-radio>
        <el-radio v-model="addForm.sex" :label="0">女</el-radio>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="addOrUpdateVisible = false">取 消</el-button>
        <el-button type="primary" @click="addOrUpdateVisible = false"
          >确 定</el-button
        >
      </span>
    </template>
  </el-dialog>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      listQuery: {
        params: "",
        current: 1,
        total: 100,
        size: 10,
      },
      addOrUpdateVisible: false,
      addForm: {},
      tableData: [],
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    getPage() {
      axios.post("http://localhost:8090/users", this.listQuery).then((res) => {
        this.tableData = res.data.data.users;
        this.listQuery.total = res.data.data.total;
      });
    },
    update(row) {
      console.log(1111111111111111111111111111);
      console.log(row);
      (this.title = "修改${row.userName}"), (this.addForm = row);
      this.addOrUpdateVisible = true;
    },
    remove(row) {
      this.$confirm(`确认删除${row.userName}吗`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$message({
          type: "success",
          message: "删除成功",
        });
      });
    },
  },
};
</script>